package cn.csust.net2.manager.client.panel;

import java.sql.Date;

import cn.csust.net2.manager.client.app.App;
import cn.csust.net2.manager.client.ux.BeanCombo;
import cn.csust.net2.manager.client.ux.BeanGridPanel;
import cn.csust.net2.manager.shared.po.Academy;
import cn.csust.net2.manager.shared.po.Banji;
import cn.csust.net2.manager.shared.po.Family;
import cn.csust.net2.manager.shared.po.Major;
import cn.csust.net2.manager.shared.po.Resume;
import cn.csust.net2.manager.shared.po.Student;
import cn.csust.net2.manager.shared.service.SchoolRegisterService;
import cn.csust.net2.manager.shared.service.SchoolRegisterServiceAsync;
import cn.csust.net2.manager.shared.util.ClassForNameAble;
import cn.csust.net2.manager.shared.util.Factory;
import cn.csust.net2.manager.shared.vo.Config;

import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.data.BaseListLoadConfig;
import com.extjs.gxt.ui.client.data.BeanModel;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.FormEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.FormButtonBinding;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.form.Radio;
import com.extjs.gxt.ui.client.widget.form.RadioGroup;
import com.extjs.gxt.ui.client.widget.form.TextArea;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.ColumnData;
import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
import com.extjs.gxt.ui.client.widget.layout.FormData;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.FileUpload;
import com.google.gwt.user.client.ui.Image;

@ClassForNameAble
public class EntranceRegistrationPanel extends ContentPanel {

	private FormPanel formPanel;
	private BeanCombo academyBeanCombo;
	private BeanCombo majorBeanCombo;
	private BeanCombo banjiBeanCombo;
	private SchoolRegisterServiceAsync service;
	private TextField<String> nameTextField;
	private RadioGroup sexGroup;
	private DateField birthdayDateField;
	private TextField<String> politicalAffiliationTextField;
	private TextField<String> birthplaceTextField;
	private TextField<String> nationTextField;
	private TextArea specialtyTextArea;
	private NumberField cellPhoneNumberField;
	private NumberField qqNumberField;
	private TextField<String> addressTextField;
	private NumberField postcodeNumberNumberField;
	private NumberField telephoneNumberField;

	private NumberField studentNumberNumberField;
	private DateField entryDateDateField;
	private TextField<String> gradeTextField;
	private TextField<String> dormitoryTextField;

	private BeanGridPanel<Resume> resumeGridPanel;
	private BeanGridPanel<Family> familyGridPanel;

	private boolean editable = true;
	private Student student = (Student) App.getUser();
	
	//用户头像的地址
	private String imageURL = App.getUser().getUserHead();

	public EntranceRegistrationPanel() {
		this.setHeaderVisible(false);
		service = GWT.create(SchoolRegisterService.class);
		setScrollMode(Scroll.AUTO);
		setLayout(new FlowLayout());
	}

	public EntranceRegistrationPanel(Student student, boolean isEditable) {
		this.setHeaderVisible(false);
		setScrollMode(Scroll.AUTO);
		service = GWT.create(SchoolRegisterService.class);
		setLayout(new FlowLayout());
		this.student = student;
		this.editable = isEditable;
	}
//	public EntranceRegistrationPanel(Student student, boolean isEditable) {
//		this.setHeaderVisible(false);
//		setScrollMode(Scroll.AUTO);
//		service = GWT.create(SchoolRegisterService.class);
//	//	this.service = service;
//		setLayout(new FlowLayout());
//		this.student = student;
//		this.editable = isEditable;
//	}

	/**
	 * 创建表单
	 */
	public void createForm() {
		// TODO Auto-generated method stub
		System.out.println("加载成功！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！");
		formPanel = new FormPanel();
		formPanel.setFrame(true);
		formPanel.setHeaderVisible(false);
		formPanel.setWidth("100%");
		formPanel.setLayout(new FlowLayout());

		// 基本信息
		formPanel.add(createFieldSetBasicInfo());
		// 学校信息
		formPanel.add(createFieldSetSchoolInfo());
//		// 其他
		formPanel.add(createFieldSetOtherInfo());
//
		formPanel.add(createFieldSetWork());
		
		
		formPanel.add(createFieldSetFamily());

		formPanel.setButtonAlign(HorizontalAlignment.CENTER);
		Button submitButton = new Button("提交");
		submitButton.addSelectionListener(new SelectionListener<ButtonEvent>() {
			@Override
			public void componentSelected(ButtonEvent ce) {
				// TODO Auto-generated method stub
				submit();
			}
		});
		formPanel.addButton(submitButton);
		FormButtonBinding binding = new FormButtonBinding(formPanel);
		binding.addButton(submitButton);
		Button cancelButton = new Button("取消");
		formPanel.addButton(cancelButton);

		if (!this.editable) {
			submitButton.setVisible(false);
			cancelButton.setVisible(false);
		}
		this.add(formPanel);
	}

	/**
	 * 创建基本信息表单
	 * 
	 * @return
	 */
	public FieldSet createFieldSetBasicInfo() {
		FieldSet fieldSetBasic = new FieldSet();
		fieldSetBasic.setHeading("基本信息");
		fieldSetBasic.setCollapsible(true);

		FormData formData = new FormData("100%");

		LayoutContainer main = new LayoutContainer();
		main.setLayout(new ColumnLayout());

		LayoutContainer leftBasic = new LayoutContainer();
		leftBasic.setStyleAttribute("paddingRight", "10px");
		FormLayout layout = new FormLayout();
		layout.setLabelAlign(LabelAlign.LEFT);
		leftBasic.setLayout(layout);

		// 姓名
		nameTextField = createTextField("姓名", "name", this.editable);
		nameTextField.setValue(student.getName());
		leftBasic.add(nameTextField, formData);

		// 性别
		Radio manRadio = new Radio();
		manRadio.setBoxLabel("男");

		Radio womenRadio = new Radio();
		womenRadio.setBoxLabel("女");

		if (student.getSex() != null && student.getSex().equals("女")) {
			womenRadio.setValue(true);
		} else {
			manRadio.setValue(true);
		}

		sexGroup = new RadioGroup();
		sexGroup.setFieldLabel("性别");
		sexGroup.add(manRadio);
		sexGroup.add(womenRadio);
		if (!this.editable) {
			sexGroup.setEnabled(false);
		}
		leftBasic.add(sexGroup);

		// 家庭地址
		addressTextField = createTextField("家庭地址", "address", this.editable);
		addressTextField.setValue(student.getAddress());
		leftBasic.add(addressTextField, formData);

		// 籍贯
		birthplaceTextField = createTextField("籍贯", "birthplace", this.editable);
		birthplaceTextField.setValue(student.getBirthplace());
		leftBasic.add(birthplaceTextField, formData);

		LayoutContainer rightBasic = new LayoutContainer();
		rightBasic.setStyleAttribute("paddingRight", "10px");
		layout = new FormLayout();
		layout.setLabelAlign(LabelAlign.LEFT);
		rightBasic.setLayout(layout);

		// 学号
		studentNumberNumberField = createNumberField("学号", null, false);
		long nu = student.getStudentNumber();
		System.out.println(nu);
		studentNumberNumberField.setValue(student.getUserID());
		rightBasic.add(studentNumberNumberField, formData);

		// 出生日期
		// birthdayDateField = new DateField();
		birthdayDateField = Factory.createDateFieldWithFormated();
		birthdayDateField.setFieldLabel("出生日期");
		birthdayDateField.setValue(student.getBirthday());
		birthdayDateField.setEnabled(this.editable);
		rightBasic.add(birthdayDateField, formData);

		// 邮政编码
		postcodeNumberNumberField = createNumberField("邮政编码", "postcode",
				this.editable);
		if (student.getPostcode() != null && !student.getPostcode().equals("")) {
			postcodeNumberNumberField.setValue(new Long(student.getPostcode()));
		}
		rightBasic.add(postcodeNumberNumberField, formData);

		// 民族
		nationTextField = createTextField("民族", "nation", this.editable);
		nationTextField.setValue(student.getNation());
		rightBasic.add(nationTextField, formData);

		main.add(leftBasic, new ColumnData(.5));
		main.add(rightBasic, new ColumnData(.5));
		leftBasic.setStyleAttribute("padding-right", "30px");
		rightBasic.setStyleAttribute("padding-right", "30px");
		fieldSetBasic.add(main);
		return fieldSetBasic;
	}

	/**
	 * 创建学校信息表单
	 * 
	 * @return
	 */
	public FieldSet createFieldSetSchoolInfo() {
		FieldSet fieldSetSchool = new FieldSet();
		fieldSetSchool.setHeading("学校信息");
		fieldSetSchool.setCollapsible(true);

		FormData formData = new FormData("100%");
		
		LayoutContainer main = new LayoutContainer();
		main.setLayout(new ColumnLayout());

		LayoutContainer leftSchool = new LayoutContainer();
		leftSchool.setStyleAttribute("paddingRight", "10px");
		FormLayout layoutSchool = new FormLayout();
		layoutSchool.setLabelAlign(LabelAlign.LEFT);
		leftSchool.setLayout(layoutSchool);

		// 学院
		academyBeanCombo = new BeanCombo(new Academy(), service);
		academyBeanCombo.setForceSelection(true);
		if (student.getBanji() != null && student.getBanji().getMajor() != null) {
			academyBeanCombo.setValue(Factory.createBeanModel(student
					.getBanji().getMajor().getAcademy()));
		}

		academyBeanCombo.setFieldLabel("学院");
		academyBeanCombo.setAllowBlank(false);
		academyBeanCombo.setEnabled(this.editable);
		academyBeanCombo
				.addSelectionChangedListener(new SelectionChangedListener<BeanModel>() {

					@Override
					public void selectionChanged(
							SelectionChangedEvent<BeanModel> se) {
						// TODO Auto-generated method stub
						if (academyBeanCombo.isValid()) {
							majorBeanCombo.setValue(null);
							BaseListLoadConfig config = new BaseListLoadConfig();
							config.set("academy", academyBeanCombo.getValue()
									.getBean());
							majorBeanCombo.setFilter(config);
							majorBeanCombo.getLoader().load();
							majorBeanCombo.setEnabled(true);
						}

					}
				});
		leftSchool.add(academyBeanCombo, formData);

		// 专业
		BaseListLoadConfig majorConfig = new BaseListLoadConfig();
		if (academyBeanCombo.getValue() != null) {
			majorConfig.set("academy", academyBeanCombo.getValue().getBean());
		}

		majorBeanCombo = new BeanCombo(new Major(), service, majorConfig);
		majorBeanCombo.getStore().removeAll();
		majorBeanCombo.setForceSelection(true);
		if (student.getBanji() != null) {
			majorBeanCombo.setValue(Factory.createBeanModel(student.getBanji()
					.getMajor()));
		}

		majorBeanCombo.setFieldLabel("专业");
		majorBeanCombo.setAllowBlank(false);
		if (academyBeanCombo.getValue() == null || !this.editable) {
			majorBeanCombo.setEnabled(false);
		}

		majorBeanCombo
				.addSelectionChangedListener(new SelectionChangedListener<BeanModel>() {

					@Override
					public void selectionChanged(
							SelectionChangedEvent<BeanModel> se) {
						// TODO Auto-generated method stub
						if (majorBeanCombo.isValid()) {
							banjiBeanCombo.setValue(null);
							BaseListLoadConfig config = new BaseListLoadConfig();
							config.set("major", majorBeanCombo.getValue()
									.getBean());
							banjiBeanCombo.setFilter(config);
							banjiBeanCombo.getLoader().load();
							banjiBeanCombo.setEnabled(true);
						}
					}
				});
		leftSchool.add(majorBeanCombo, formData);

		// 班级
		BaseListLoadConfig banjiConfig = new BaseListLoadConfig();
		if (majorBeanCombo.getValue() != null) {
			banjiConfig.set("major", majorBeanCombo.getValue().getBean());
		}
		banjiBeanCombo = new BeanCombo(new Banji(), service, banjiConfig);
		banjiBeanCombo.setForceSelection(true);

		banjiBeanCombo.setValue(Factory.createBeanModel(student.getBanji()));

		banjiBeanCombo.setValue(Factory.createBeanModel(student.getBanji()));
		banjiBeanCombo.setFieldLabel("班级");
		banjiBeanCombo.setAllowBlank(false);
		if (majorBeanCombo.getValue() == null || !this.editable) {
			banjiBeanCombo.setEnabled(false);
		}

		leftSchool.add(banjiBeanCombo, formData);

		// 年级
		gradeTextField = createTextField("年级", "grade", this.editable);
		gradeTextField.setEnabled(false);
		gradeTextField.setValue("2009级");

		leftSchool.add(gradeTextField, formData);

		LayoutContainer rightSchool = new LayoutContainer();
		rightSchool.setStyleAttribute("paddingRight", "10px");
		layoutSchool = new FormLayout();
		layoutSchool.setLabelAlign(LabelAlign.LEFT);
		rightSchool.setLayout(layoutSchool);

		// 入学日期
		entryDateDateField = Factory.createDateFieldWithFormated();
		entryDateDateField.setFieldLabel("入学日期");
		entryDateDateField.setEnabled(this.editable);
		entryDateDateField.setValue(student.getEntryDate());
		rightSchool.add(entryDateDateField, formData);

		// 政治面貌
		politicalAffiliationTextField = createTextField("政治面貌",
				"politicalAffiliation", this.editable);
		politicalAffiliationTextField.setValue(student
				.getPoliticalAffiliation());
		rightSchool.add(politicalAffiliationTextField, formData);

		// 寝室
		dormitoryTextField = createTextField("寝室", "dormitory", this.editable);
		dormitoryTextField.setValue(student.getDormitory());
		rightSchool.add(dormitoryTextField, formData);

		main.add(leftSchool, new ColumnData(.5));
		main.add(rightSchool, new ColumnData(.5));
		leftSchool.setStyleAttribute("padding-right", "30px");
		rightSchool.setStyleAttribute("padding-right", "30px");
		fieldSetSchool.add(main);
		return fieldSetSchool;
	}

	/**
	 * 创建其他信息表单
	 * 
	 * @return
	 */
	public FieldSet createFieldSetOtherInfo() {
		FieldSet fieldSetOther = new FieldSet();
		fieldSetOther.setHeading("其他信息");
		fieldSetOther.setCollapsible(true);

		FormData formData = new FormData("100%");
		
		LayoutContainer main = new LayoutContainer();
		main.setLayout(new ColumnLayout());

		LayoutContainer leftOther = new LayoutContainer();

		ContentPanel photo = createPhotoFormPanel();
		leftOther.add(photo);

		LayoutContainer rightOther = new LayoutContainer();
		FormLayout layoutOther = new FormLayout();
		layoutOther.setLabelAlign(LabelAlign.LEFT);
		layoutOther.setLabelWidth(70);
		rightOther.setLayout(layoutOther);

		// 手机号码
		cellPhoneNumberField = createNumberField("手机号码", "cellPhone",
				this.editable);
		if (student.getCellPhone() != null
				&& !student.getCellPhone().equals(""))
			cellPhoneNumberField.setValue(new Long(student.getCellPhone()));
		rightOther.add(cellPhoneNumberField, formData);

		// 电话号码
		telephoneNumberField = createNumberField("电话", "telephone",
				this.editable);
		if (student.getTelephone() != null
				&& !student.getTelephone().equals(""))
			telephoneNumberField.setValue(new Long(student.getTelephone()));
		rightOther.add(telephoneNumberField, formData);

		// QQ号码 

		qqNumberField = createNumberField("QQ", "qq", this.editable);
		if (student.getQq() != null && !student.getQq().equals(""))
			qqNumberField.setValue(new Long(student.getQq()));
		rightOther.add(qqNumberField, formData);

		// 特长
		specialtyTextArea = new TextArea();
		specialtyTextArea.setName("specialty");
		specialtyTextArea.setPreventScrollbars(true);
		specialtyTextArea.setFieldLabel("特长");
		specialtyTextArea.setValue(student.getSpecialty());
		specialtyTextArea.setEnabled(this.editable);
		rightOther.add(specialtyTextArea, formData);

		main.add(leftOther, new ColumnData(250));
		main.add(rightOther, new ColumnData(.8));
		fieldSetOther.add(main);
		return fieldSetOther;
	}

	public ContentPanel createPhotoFormPanel() {
		final ContentPanel panel = new ContentPanel();
		panel.setHeaderVisible(false);
		formPanel.setAction(GWT.getModuleBaseURL() + "UploadPhoto");
		
		// Because we're going to add a FileUpload widget, we'll need to set the
		// form to use the POST method, and multipart MIME encoding.
		formPanel.setEncoding(FormPanel.Encoding.MULTIPART);
		formPanel.setMethod(FormPanel.Method.POST);

		final ContentPanel photoPanel = new ContentPanel();
		final Image image = new Image();
		if(imageURL==null || imageURL.equals("")) {
			image.setUrl("images/userHead/default_person.gif");
		} else {
			image.setUrl(GWT.getModuleBaseURL() + "download_center.do?type=P");
		}
		
		image.setSize("215px", "250px");
		image.setVisible(true);
		photoPanel.add(image);

		photoPanel.setHeaderVisible(false);
		photoPanel.setFrame(true);
		photoPanel.setSize(215, 250);
		panel.add(photoPanel);

		FileUpload upload = new FileUpload();
		upload.setName("upload");
		panel.add(upload);
		upload.setEnabled(editable);
		Button submit = new Button("开始上传",
				new SelectionListener<ButtonEvent>() {

					@Override
					public void componentSelected(ButtonEvent ce) {
						// TODO Auto-generated method stub
						image.setUrl("images/loading.gif");
						formPanel.submit();
					}
				});
		submit.setEnabled(editable);
		formPanel.addListener(Events.Submit, new Listener<FormEvent>() {

			@Override
			public void handleEvent(FormEvent be) {
				// TODO Auto-generated method stub
				String fileName = be.getResultHtml();
				if(!fileName.equals("") && fileName!=null) {
					image.setUrl("images/userHead/" + fileName);
					imageURL =   fileName;
				} else {
					if(imageURL==null || imageURL.equals("")) {
						image.setUrl("images/userHead/default_person.gif");
					} else {
						image.setUrl(GWT.getModuleBaseURL() + "download_center.do?type=P");
					}
					MessageBox.alert("警告", "对不起，你的图片格式有误，请重新选择图片，图片格式应为jpg, png, gif, bmp", null);
				}
				
			}
		});
		panel.setButtonAlign(HorizontalAlignment.CENTER);
		panel.addButton(submit);
		return panel;
	}

	/**
	 * 创建个人简历表格
	 * 
	 * @return
	 */
	public FieldSet createFieldSetWork() {
		FieldSet fieldSetOther = new FieldSet();
		fieldSetOther.setHeading("个人简历");
		fieldSetOther.setCollapsible(true);
		fieldSetOther.setLayout(new FitLayout());

		resumeGridPanel = new BeanGridPanel<Resume>(new Resume(), this.service);
		resumeGridPanel.setDatabase(false);
		resumeGridPanel.setSaveButton(false);
		resumeGridPanel.setPagingToolBar(false);
		if (!editable) {
			resumeGridPanel.setToolBar(false);
		}

		resumeGridPanel.createDefault();
		Config c = new Config();
		c.put("student", student);
		resumeGridPanel.load(c);
		fieldSetOther.add(resumeGridPanel);
		return fieldSetOther;
	}

	/**
	 * 创建家庭成员表格
	 * 
	 * @return
	 */
	public FieldSet createFieldSetFamily() {
		FieldSet fieldSetOther = new FieldSet();
		fieldSetOther.setHeading("家庭成员");
		fieldSetOther.setCollapsible(true);
		fieldSetOther.setLayout(new FitLayout());

		familyGridPanel = new BeanGridPanel<Family>(new Family(), this.service);
		familyGridPanel.setDatabase(false);
		familyGridPanel.setSaveButton(false);
		familyGridPanel.setPagingToolBar(false);
		if (!editable) {
			familyGridPanel.setToolBar(false);
		}

		familyGridPanel.createDefault();
		Config c = new Config();
		c.put("student", student);
		familyGridPanel.load(c);
		fieldSetOther.add(familyGridPanel);
		return fieldSetOther;
	}

	/**
	 * 根据labelName和name创建一个TextField
	 * 
	 * @param labelName
	 * @param name
	 * @return
	 */
	public TextField<String> createTextField(String labelName, String name,
			boolean editable) {
		TextField<String> textField = new TextField<String>();
		textField.setFieldLabel(labelName);
		textField.setName(name);
		textField.setEnabled(editable);
		return textField;
	}

	/**
	 * 根据labelName和name创建一个NumberField
	 * 
	 * @param labelName
	 * @param name
	 * @return
	 */
	public NumberField createNumberField(String labelName, String name,
			boolean editable) {
		NumberField numberField = new NumberField();
		numberField.setFieldLabel(labelName);
		numberField.setName(name);
		numberField.setEnabled(editable);
		return numberField;
	}

	/**
	 * 提交表单，完成注册，考虑IE兼容的问题，不能在一个表单中存放另外一个
	 * 表单，所以将表单用于上传图片的提交，本方法用RPC进行提交
	 */
	public void submit() {
		if (formPanel.isValid()) {
			Student student = (Student) App.getUser();
			student.setName(nameTextField.getRawValue());
			student.setSex(sexGroup.getValue().getBoxLabel());
			if (birthdayDateField.getDatePicker().getValue() != null) {
				student.setBirthday(new Date(birthdayDateField.getDatePicker()
						.getValue().getTime()));
			}

			student.setPoliticalAffiliation(politicalAffiliationTextField
					.getRawValue());
			student.setBirthplace(birthplaceTextField.getRawValue());
			student.setNation(nationTextField.getRawValue());
			student.setSpecialty(specialtyTextArea.getRawValue());
			student.setCellPhone(cellPhoneNumberField.getRawValue());
			student.setQq(qqNumberField.getRawValue());
			student.setAddress(addressTextField.getRawValue());
			student.setPostcode(postcodeNumberNumberField.getRawValue());
			student.setTelephone(telephoneNumberField.getRawValue());
			if (entryDateDateField.getDatePicker().getValue() != null) {
				student.setEntryDate(new Date(entryDateDateField
						.getDatePicker().getValue().getTime()));
			}

			student.setDormitory(dormitoryTextField.getRawValue());
			BeanModel banjiBeanModel = banjiBeanCombo.getValue();
			Banji banji = banjiBeanModel.getBean();
			student.setBanji(banji);
			
			student.setUserHead(imageURL);
			student.setRegister(1);
			SchoolRegisterServiceAsync service = GWT.create(SchoolRegisterService.class);
			
			service.update(student, new AsyncCallback<Void>() {
				
				@Override
				public void onSuccess(Void result) {
					// TODO Auto-generated method stub
					App.getHeadPanel().getImage().setUrl(imageURL);
					MessageBox.alert("提示", "注册成功!!!", null);
				}
				
				@Override
				public void onFailure(Throwable caught) {
					// TODO Auto-generated method stub
					
				}
			});

			resumeGridPanel.save();
			familyGridPanel.save();
		}

	}

}
